var subjectname = "";
var subjectname2 = "";

function AJAXselect(sql,flag,name)
{
  subjectname = name;
  var url = "/AJAXselect?sql="+sql+"&flag="+flag;
  if (window.XMLHttpRequest) 
    { 
      req = new XMLHttpRequest(); 
    }
  else if (window.ActiveXObject) 
    { 
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    if(req)
	{ 
      req.open("GET",url, true); 
      req.onreadystatechange = completeselect; 
      req.send(null); 
     } 
}
function completeselect()
{    
   if (req.readyState == 4){ 
     if (req.status == 200)  {  
        var text = req.responseXML.getElementsByTagName("text"); 
        var value = req.responseXML.getElementsByTagName("value"); 
		
		var str=new Array();
        var id =new Array();

		for(var i=0;i<text.length;i++)
	    {
		   str[i]=text[i].firstChild.data;
	  	   id[i] =value[i].firstChild.data;
        }
           buildSelectis(id,str,document.getElementById(subjectname));
     }
  }
}


function AJAXselect2(sql,flag,name)
{
  subjectname2 = name;
  var url = "/AJAXselect?sql="+sql+"&flag="+flag;
  if (window.XMLHttpRequest) 
    { 
      req2 = new XMLHttpRequest(); 
    }
  else if (window.ActiveXObject) 
    { 
      req2 = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    if(req2)
	{ 
      req2.open("GET",url, true); 
      req2.onreadystatechange = completeselect2; 
      req2.send(null); 
     } 
}
function completeselect2()
{    
   if (req2.readyState == 4){ 
     if (req2.status == 200)  {  
        var text = req2.responseXML.getElementsByTagName("text"); 
        var value = req2.responseXML.getElementsByTagName("value"); 
		
		var str=new Array();
        var id =new Array();

		for(var i=0;i<text.length;i++)
	    {
		   str[i]=text[i].firstChild.data;
	  	   id[i] =value[i].firstChild.data;
        }
        buildSelectis(id,str,document.all[subjectname2]);
     }
  }
}
function buildSelectis(id,str,sel) 
{ 
  sel.options.length=0;
  for(var i=0;i<str.length;i++) 
  {
   sel.options[sel.options.length]=new Option(str[i],id[i]);
  }
}

function selectHasFirstOption(sql,flag,name,firstValue)
{
  subjectname = name;
  var url = "/AJAXselect?sql="+sql+"&flag="+flag+"&first="+firstValue;
  if (window.XMLHttpRequest) 
    { 
      req = new XMLHttpRequest(); 
    }
  else if (window.ActiveXObject) 
    { 
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    if(req)
	{ 
      req.open("GET",url, true); 
      req.onreadystatechange = completeselect; 
      req.send(null); 
     } 
}